package com.bdqn.zhao.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.zhao.dao.IpParkimgMapper;
import com.bdqn.zhao.pojo.IpParkimg;
import com.bdqn.zhao.service.IpParkimgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 园区图片表 服务实现类
 * </p>
 *
 * @author zhangsan
 * @since 2023-05-10
 */
@Service
public class IpParkimgServiceImpl extends ServiceImpl<IpParkimgMapper, IpParkimg> implements IpParkimgService {

    @Autowired
    public IpParkimgMapper ipParkimgMapper;

    @Override
    public Map<String, Object> deleteImage(int parkimgId) {
        HashMap<String, Object> map = new HashMap<>();
        // 1.通过 id 查询商品图片表
        QueryWrapper<IpParkimg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parkimgId", parkimgId);
        IpParkimg ipParkimg = ipParkimgMapper.selectOne(queryWrapper);
        // 2. 获取该图片的属性值 进行判断是 小图--还是--banner图
        if (ipParkimg.getParkimgType() == 0) {
            //3. 如果是 0 删除小图-  1 删除banner图
            boolean flag = new File("D:\\sanqi\\mall\\src\\main\\webapp\\res\\images\\item\\productSinglePicture\\" + ipParkimg.getParkimgSrc()).delete();
        } else {
            boolean flag = new File("D:\\sanqi\\mall\\src\\main\\webapp\\res\\images\\item\\productDetailsPicture\\" + ipParkimg.getParkimgSrc()).delete();
        }
        if (ipParkimgMapper.delete(queryWrapper) > 0) {
            map.put("success", true);
        } else {
            map.put("success", false);
        }
        return map;
    }
}
